import { Client } from 'minio';
import { env } from './env';

export const minio = new Client({
  endPoint: env.minio.endPoint,
  port: env.minio.port,
  useSSL: env.minio.useSSL,
  accessKey: env.minio.accessKey,
  secretKey: env.minio.secretKey
});

// 可选：自动创建桶（bucket）
async function ensureBucketExists() {
  const exists = await minio.bucketExists(env.minio.bucket);
  if (!exists) {
    await minio.makeBucket(env.minio.bucket, 'us-east-1');
    console.log(`✅ MinIO bucket "${env.minio.bucket}" created`);
  } else {
    console.log(`✅ MinIO bucket "${env.minio.bucket}" already exists`);
  }
}

ensureBucketExists().catch(console.error);
